@extends('admin.layout.base')
@section('styles')
@endsection
@section('content')
    <div class="panel-content" id="app" v-cloak>
        <div class="panel-body">
            <div class="panel-header">
                <div class="panel-title"> 任务记录【{{ $demand_title }}】 </div>
                <el-tabs v-model="tabValue" type="card" @tab-click="search()"></el-tabs>
            </div>
            <div class="panel-main">
                <div class="panel-btns">
                    <el-button type="success" icon="fa fa-refresh" @click="list()" size="small"> 刷新</el-button>
                    <el-button type="primary" icon="fa fa-plus" @click="exports()" size="small"> 导出</el-button>
                </div>
                <el-table v-loading="loading"
                          element-loading-text="努力加载中..."
                          element-loading-spinner="el-icon-loading"
                          ref="multipleHandle"
                          tooltip-effect="dark"
                          sortable='custom'
                          @sort-change="sortChange"
                          @selection-change="handleSelectionChange"
                          :data="listData.data" border>
                    <el-table-column align="center" type="selection" width="30"></el-table-column>
                    <el-table-column align="center" prop="id" label="编号" width="50"></el-table-column>
                   
                    <el-table-column align="center" label="任务标题" width="300">
                    	<template slot-scope="scope"> 
                    		<span v-html="scope.row.demand.title"></span>
                    	</template>
                    </el-table-column>
                    <el-table-column align="center" label="悬赏主" width="120">
                    	<template slot-scope="scope"> 
                    		<span v-html="scope.row.demand.user_name"></span>
                    	</template>
                    </el-table-column>

                    <el-table-column align="center" prop="contract_price" label="任务金额" width="110">
                    	<template slot-scope="scope"> 
                    		<span v-html="scope.row.demand.price"></span>
                    	</template>
                    </el-table-column>
                    
                    <el-table-column align="center" label="猎人信息" width="250">
                    	<template slot-scope="scope"> 
                    		<span v-html="scope.row.userinfo.nickname"></span>【<span v-html="scope.row.userinfo.mobile"></span>】 
                    	
                    	</template>
                    </el-table-column>
                    
                    <el-table-column align="center" prop="get_money" label="猎人收益" width="110">
                    
                    </el-table-column>
                    
                    <el-table-column align="center" prop="created_at" label="接受时间" width="200">
                    
                    </el-table-column>
                      <el-table-column align="center" prop="end_time" label="任务结束时间" width="200">
                    
                    </el-table-column>
                    <el-table-column align="center" label="任务状态" width="150">
                        <template slot-scope="scope"> 
                        	<span v-html="scope.row.status_text"></span> 
                    	</template>
                    </el-table-column>
                    <el-table-column label="操作">
                    
                        <template slot-scope="scope">
                            <el-button v-if="scope.row.demand.user_id == 0 && scope.row.status == 2 && scope.row.check_status == 0" @click="active(scope.row.id)" icon="fa fa-unlock-alt" type="success" size="mini" plain>通过</el-button>
                            <el-button v-if="scope.row.demand.user_id == 0 && scope.row.status == 2 && scope.row.check_status == 0" @click="edit(scope.row.id)" icon="fa fa-lock" type="danger" size="mini" plain>驳回</el-button>                            
                       		<el-button @click="edit(scope.row.id)" icon="fa fa-edit" type="primary" size="mini" plain> 查看</el-button>
                        </template>
                    </el-table-column>
                   
                </el-table>
                <div class="pagination"  v-if="listData && listData.total">
                    <div class="pagination-total">共 <em> @{{listData.total}} </em> 条记录</div>
                    <el-pagination v-if="listData.last_page > 1"
                                   background
                                   :page-size="listData.per_page"
                                   layout="prev, pager, next, jumper"
                                   :total="listData.total"
                                   prev-text="上一页"
                                   next-text="下一页"
                                   :current-page="listData.current_page"
                                   @current-change="changePage">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script src="{{ asset('js/moment.min.js') }}" type="text/javascript"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data: function() {
                return {
                    listData: [],//列表数据
                    cateCascader: [],//连级类目
                    tabValue: 0,//tab
                    date: null,//日期范围
                    params: {kwd:'', name:'', page:1, status:0, start:'', end:'', cid:0, sort:''},
                    loading: false,
                    multipleSelection:[],//多选项
                    state:0,//当前需求是否有人中标 0:没有 1:有
                }
            },
            created(){
                this.params.demand_id = " {{ $demand_id }}";
                this.list();
            },
            methods: {
                //分页
                changePage(val) {
                    this.params.page = val;
                    this.list();
                },
                edit(id){
                    window.location.href = "{{ route('admin.bin.edit') }}" + '?id=' + id;
                },
                //列表
                list(){
                    let that = this;
                    this.loading = true;
                    setTimeout(()=>{
                        $.get("{{ route('admin.bid.list') }}",this.params,function (res) {
                            if(res.code){
                                that.$message.error(res.msg);
                            }else{
                                that.listData = res.data;
                               
                                that.loading = false;
                            }
                        },'JSON');
                    },500);
                },
                //激活
                active(id){
                    let that = this;
                    $.post("{{ route('admin.bid.active') }}",{id: id, _token: "{{csrf_token()}}"},function (res) {
                        if(res.code){
                            that.$message.error(res.msg);
                        }else{
                            that.list();
                        }
                    },'JSON');
                },
                //驳回
                lock(id){
                    let that = this;
                    $.post("{{ route('admin.bid.lock') }}",{id: id, _token: "{{csrf_token()}}"},function (res) {
                        if(res.code){
                            that.$message.error(res.msg);
                        }else{
                            that.list();
                        }
                    },'JSON');
                },
                exports(){
                    if(this.multipleSelection.length == 0){
                        var msg = '确定要导出所有的任务信息吗？';
                    }else {
                        var msg = '确定要导出选择的任务信息吗？';
                    }
                    
                    this.$confirm(msg, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        
                        alert({{ $demand_id }});
                        window.location.href = "{{ route('admin.bin.exports') }}"+'?&ids="{{ $demand_id }}"';
                    }).catch(() => {});
                },
                //排序
                sortChange(column){
                    switch (column.order) {
                        case 'ascending':
                            this.params.sort = 'asc';
                            break;
                        case 'descending':
                            this.params.sort = 'desc';
                            break;
                        default:
                            break;
                    }
                    this.list();
                },
                // 多选删除
                multiDelete(){
                    if(this.multipleSelection.length == 0){
                        this.$message.error('请至少选择一项你要删除的项');return false;
                    }
                    this.destroy(this.multipleSelection);
                },
                handleSelectionChange(val) {
                    let select = [];
                    if(val.length > 0){
                        val.filter((item)=>{
                            if(select.indexOf(item.id) === -1){
                                select.push(item.id)
                            }
                        });
                        this.multipleSelection = select;
                    }else{
                        this.multipleSelection = [];
                    }
                },
                //删除
                destroy(id){
                    let that = this;
                    this.$confirm('确定要删除选中的活动信息吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.post("{{ route('admin.bid.destroy') }}",{id: id, _token: "{{csrf_token()}}"},function (res) {
                            if(res.code){
                                that.$message.error(res.msg);
                            }else{
                                that.list();
                            }
                        },'JSON');
                    }).catch(() => {});
                },
            }
        });
    </script>
@endsection
